package com.ming.seatMonitoring.controller;

import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ming.seatMonitoring.pojo.DO.BookRoomInfoDO;
import com.ming.seatMonitoring.pojo.DO.RoomInfoDO;
import com.ming.seatMonitoring.pojo.entity.ResultBody;
import com.ming.seatMonitoring.service.BookRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

/**
 * @author 小明
 * @date 2021/10/22
 * @description
 */
@RestController
@RequestMapping("/bookRoom")
public class BookRoomController {
    @Autowired
    private BookRoomService bookRoomService;

    /**
     * 添加预订信息
     * @param bookInfo
     * @return
     */
    @RequestMapping("add")
    public ResultBody addBookRoomInfo(@RequestBody BookRoomInfoDO bookInfo){
        final boolean b = bookRoomService.addBookInfo(bookInfo);
        if (b){
            return ResultBody.ok().message("添加成功");
        }
        return ResultBody.ok().message("添加失败，请重试");
    }

    /**
     * 伪删除房间预订信息，添加deleteTime
     * @param roomId
     * @return
     */
    @RequestMapping("delete")
    public ResultBody deleteBookInfo(@RequestParam int roomId){
        final boolean b = bookRoomService.deleteBookInfo(roomId);
        if (b){
            return ResultBody.ok().message("删除成功");
        }
        return ResultBody.ok().message("删除失败，请重试");
    }

    /**
     * 修改房间预订信息
     * @param bookInfo
     * @return
     */
    @RequestMapping("/update")
    public ResultBody updateBookInfo(@RequestBody BookRoomInfoDO bookInfo){
        final boolean b = bookRoomService.updateBookInfo(bookInfo);
        if (b){
            return ResultBody.ok().message("更新成功");
        }
        return ResultBody.ok().message("更新失败，请重试");
    }

    /**
     * 分页查询所有房间预订信息
     * @param pageNumber
     * @param size
     * @return
     */
    @RequestMapping("/selectPage")
    public ResultBody getBookInfo(@RequestParam(defaultValue = "1") @NotEmpty String pageNumber,
                                  @RequestParam(defaultValue = "10") @NotEmpty String size){
        Long PageNumber = Long.valueOf(pageNumber);
        Long Size = Long.valueOf(size);
        Page<BookRoomInfoDO> page = new Page<>(PageNumber,Size);
        Page<BookRoomInfoDO> bookInfo = bookRoomService.getBookInfo(page);
        return ResultBody.ok().data("bookInfo",bookInfo);
    }

    /**
     * 通过房间号查询预订信息
     * @param roomId
     * @return
     */
    @RequestMapping("/searchById")
    public ResultBody searchBookInfo(@RequestParam int roomId){
        return ResultBody.ok().data("bookInfo",bookRoomService.searchBookInfo(roomId));
    }

    /**
     * 用过id查询预订信息
     * @param id
     * @return
     */
    @RequestMapping("/getById")
    public ResultBody getById(@RequestParam int id){
        final BookRoomInfoDO byId = bookRoomService.getById(id);
        System.out.println(byId);
        return ResultBody.ok().data("date",byId);
    }
}
